<?php

namespace Home\Controller;

use Home\Core\CommandSDK;

class AdminListController extends BaseController
{
    /**
     * 检索区域管理员列表
     */
    public function admin_list()
    {
        $param=I('get.');
        if(empty(I('pageid'))){
            $param['pageid']=1;
        }else{
            $param['pageid']=I('pageid');
        }
        if(empty(I('pagecount'))){
            $param['pagecount']=10;
        }else{
            $param['pagecount']=I('pagecount');
        }
        $param['role']=2;
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::GetClientList, $param, 'GET');
        $array = json_decode(json_encode($return), true);
        foreach($array['accounts'] as &$value){   // 获取区域组成字符串
            foreach($value['manageareas'] as $manageareas){
                $value['areas'] .= $manageareas['areaname'].';';
            }
        }
        $pageid=$param['pageid'];
        $pagecount=$param['pagecount'];
        $totnum=$return->totnum;
        $pagenum=$totnum/$pagecount;
        $this->assign('pageid', $pageid);//页数
        $this->assign('pagecount', $pagecount);//每页显示条数
        $this->assign('pagenum', $pagenum);//总页数
        $this->assign('totnum', $totnum); //总条数
        $this->assign('param',$param);   // 搜索条件
        $this->assign('array', $array);
        $this->display();
    }
    /**
     * 获取区域管理员信息
     */
    public function GetUserInfo()
    {
        $param = I('post.');
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::GetUserInfo, $param, 'GET');
        $array = json_decode(json_encode($return), true);
        $array['msg']=$sdk::error_code[$return->result];
        $this->ajaxReturn($array);
    }

    /**
     * 添加区域管理员
     */
    public function AddUser_post()
    {
        $param = I('post.');
        unset($param['cpasswd']);
        $passwd=$param['passwd'];
        $param['passwd']=substr(md5("$passwd"),0,16);
        $param['role']=2;//角色
        $param['depid']=0;
        $param['validDate']=0;
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::AddUser, $param, 'GET');
        $array = json_decode(json_encode($return), true);
        $array['msg']=$sdk::error_code[$return->result];
        $this->ajaxReturn($array);
    }

    /**
     * 修改区域管理员
     */
    public function modifyUser_post()
    {
        $param = I('post.');
        $param['validDate']=0;
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::ModifyUser, $param, 'GET');
        $array = json_decode(json_encode($return), true);
        $array['msg']=$sdk::error_code[$return->result];
        $this->ajaxReturn($array);
    }

    /**
     * 删除区域管理员
     */
    public function delUser_post()
    {
        $param = I('post.');
        $sdk = new CommandSDK();
        $return = $this->http_request($sdk::DelUser, $param, 'GET');
        $array = json_decode(json_encode($return), true);
        $array['msg']=$sdk::error_code[$return->result];
        $this->ajaxReturn($array);
    }


}